﻿using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Common.Dao;

namespace Analyze.Manager
{
    public class ManWordManager
    {
        private static readonly object Lock = new object();

        private readonly List<string> _manWords;
        
        private static ManWordManager _instance;


        public static ManWordManager GetInstance()
        {
            if (null == _instance)
            {
                lock (Lock)
                {
                    _instance = new ManWordManager();
                }
            }
            return _instance;
        }

        private ManWordManager()
        {
            var classifyModels = ClassifyModelManDao.GetClassifyModel();
            _manWords = classifyModels.Select(m => m.Word).Distinct().ToList();
        }
            
        public List<string> GetManWords(string content)
        {
            var manWords = new List<string>();
            
            foreach (var manWord in _manWords)
            {
                if (content.Contains(manWord) && !manWords.Contains(manWord))
                {
                    manWords.Add(manWord);
                }
            }
            return manWords;
        }
    }
}